<template>
	<view>
		<template v-if="detInfo != null">
			<que-det :detInfo="detInfo" @dzQue="dzQue"></que-det>
			<!-- anslist -->
			<block v-if="isHasDataFlag">
				<view class="listAnsTit">解答<text class="ansLen">({{answerList.length}}条回复)</text></view>
				<view class="listWrap">
					<ans-list :answerList="answerList"></ans-list>
				</view>
				<loading-view :loading="loading"></loading-view>
			</block>
			<block v-else>
				<no-data></no-data>
			</block>
		</template>
	</view>
</template>

<script>
	import QueDet from './components/QueDet'
	import AnsList from './components/AnsList'
	import { getQueDet,addOrCancelUp } from '@/api/ansQue/index'
	export default {
		components:{
			QueDet,
			AnsList
		},
		data(){
			return{
				currOpt:'',
				nowPage:1,
				loading:false,
				queId:'',
				detInfo:null,
				answerList:[],
				isHasDataFlag:null,
				currIndex:-1,
				tabIndex:-1
			}
		},
		onLoad(options){
			this.queId = options.queId;
			this.tabIndex = options.tabIndex;
			this.currIndex = options.currIndex;
			this.getQueDetInfo();
		},
		onPullDownRefresh : function(){
			this.initParams();
			uni.stopPullDownRefresh();
		},
		methods:{
			//点赞问题
			dzQue(){
				var field = { askId:this.queId };
				addOrCancelUp(field).then(res=>{
					this.detInfo.dzTag = this.detInfo.dzTag == 1 ? 0 : 1;
					let pages = getCurrentPages();
					let prevPage = pages[pages.length - 2];
					if(this.detInfo.dzTag == 1){
						this.detInfo.upNum += 1;
						prevPage.$vm.ansQueList[this.tabIndex].list[this.currIndex].askUpNum += 1;
					}else{
						this.detInfo.upNum -= 1;
						prevPage.$vm.ansQueList[this.tabIndex].list[this.currIndex].askUpNum -= 1;
					}
				}).catch(err=>{
					console.log(err)
				});
			},
			getQueDetInfo(){
				uni.showLoading({
					mask:true,
					title:'加载中...'
				})
				var field = { parentId:this.queId,page:this.nowPage,limit:this.limit };
				let { nowPage,answerList } = this;
				this.loading = true;
				getQueDet(field).then(res=>{
					if(this.nowPage == 1){
						this.detInfo = res.data.datas;
						if(res.data.datas.answerList.length == 0){
							this.loading = false;
							this.isHasDataFlag=false;
						}
					}
					if(res.data.datas.answerList.length > 0){
						nowPage += 1;
						answerList.push( ...res.data.datas.answerList );
						this.answerList = answerList;
						this.nowPage = nowPage;
						this.loading = false;
						this.isHasDataFlag = true;
					}else{
						if(this.nowPage > 1){
							this.loading = false;
						}
					}
				}).catch(err=>{
					console.log(err)
				});
			},
			initParams(){
				this.nowPage = 1;
				this.loading = false;
				this.answerList = [];
				this.getQueDetInfo();
			}
			// ansMyQue(){
			// 	uni.navigateTo({
			// 		url:'../replayMyQue/replayMyQue'
			// 	})
			// }
		}
	}
</script>

<style lang='scss'>
	.listWrap{
		padding: 0 30rpx;
		background: #fff;
	}
	.listAnsTit{
		background: #fff;
		padding: 0 30rpx;
		font-size: $font-size32;
		color: $pss-text-color3;
		font-weight: bold;
		height: 80rpx;
		line-height: 80rpx;
		margin-top: 20rpx;
		.ansLen{
			font-size: $font-size26;
			font-weight: normal;
			margin-left: 5rpx;
		}
	}
	page{
		background: $pss-bg-primary;
	}
</style>